package com.spvs.system.service.impl;

import java.util.List;

import com.spvs.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spvs.system.mapper.SysUserAutographMapper;
import com.spvs.system.domain.SysUserAutograph;
import com.spvs.system.service.ISysUserAutographService;

/**
 * 用户签名Service业务层处理
 *
 * @author supervision
 * @date 2024-06-23
 */
@Service
public class SysUserAutographServiceImpl implements ISysUserAutographService
{
    @Autowired
    private SysUserAutographMapper sysUserAutographMapper;

    /**
     * 查询用户签名
     *
     * @return 用户签名
     */
    @Override
    public SysUserAutograph selectSysUserAutographByUserId(Long userId)
    {
        if (userId == null || userId == 0L){
            userId = SecurityUtils.getUserId();
        }
        return sysUserAutographMapper.selectSysUserAutographByUserId(userId);
    }

    /**
     * 查询用户签名列表
     *
     * @param sysUserAutograph 用户签名
     * @return 用户签名
     */
    @Override
    public List<SysUserAutograph> selectSysUserAutographList(SysUserAutograph sysUserAutograph)
    {
        return sysUserAutographMapper.selectSysUserAutographList(sysUserAutograph);
    }

    /**
     * 新增用户签名
     *
     * @param sysUserAutograph 用户签名
     * @return 结果
     */
    @Override
    public int insertSysUserAutograph(SysUserAutograph sysUserAutograph)
    {
        sysUserAutograph.setUserId(SecurityUtils.getUserId());
        return sysUserAutographMapper.insertSysUserAutograph(sysUserAutograph);
    }

    /**
     * 修改用户签名
     *
     * @param sysUserAutograph 用户签名
     * @return 结果
     */
    @Override
    public int updateSysUserAutograph(SysUserAutograph sysUserAutograph)
    {
        sysUserAutograph.setUserId(SecurityUtils.getUserId());
        //判断用户之前是否有用户签名照
        SysUserAutograph byUserId = sysUserAutographMapper.selectSysUserAutographByUserId(SecurityUtils.getUserId());
        if (byUserId == null){
            return sysUserAutographMapper.insertSysUserAutograph(sysUserAutograph);
        }else{
            return sysUserAutographMapper.updateSysUserAutograph(sysUserAutograph);
        }
    }

    /**
     * 批量删除用户签名
     *
     * @param userIds 需要删除的用户签名主键
     * @return 结果
     */
    @Override
    public int deleteSysUserAutographByUserIds(Long[] userIds)
    {
        return sysUserAutographMapper.deleteSysUserAutographByUserIds(userIds);
    }

    /**
     * 删除用户签名信息
     *
     * @param userId 用户签名主键
     * @return 结果
     */
    @Override
    public int deleteSysUserAutographByUserId(Long userId)
    {
        return sysUserAutographMapper.deleteSysUserAutographByUserId(userId);
    }
}
